package com.example.xinhuazidian.adapter

import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.xinhuazidian.R
import com.example.xinhuazidian.bean.Qianjiashi

class Qianjiashi2Adapter(private val list: MutableList<Qianjiashi.ContentBeanX.ContentBean>) :
    RecyclerView.Adapter<Qianjiashi2Adapter.MyViewHolder>() {

    inner class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val tvTitle: TextView = view.findViewById(R.id.tvTitle)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
        val view =
            LayoutInflater.from(parent.context).inflate(R.layout.item_shuimotangshi, parent, false)
        return MyViewHolder(view)
    }

    private var mOnItem2ClickListener: OnRecyclerItem2ClickListener? = null

    fun setRecyclerItem2ClickListener(listener: OnRecyclerItem2ClickListener?) {
        mOnItem2ClickListener = listener
    }

    interface OnRecyclerItem2ClickListener {
        fun onRecyclerItem2Click(position: Int)
    }

    @SuppressLint("SetTextI18n")
    override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
        val list = list[position]
        with(holder) {
            tvTitle.text = "${list.chapter} · ${list.author}"

            tvTitle.setOnClickListener {
                mOnItem2ClickListener?.onRecyclerItem2Click(position)
            }
        }
    }

    override fun getItemCount() = list.size
}
